import javax.servlet.annotation.WebServlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    private LoginHandler successHandler = new SuccessHandler();
    private LoginHandler addHandler = new AddHandler();
    private editorHandler editorHandler=new editorHandler();
    private updetaler updetaler=new updetaler();

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 提供登录表单页面的GET请求处理逻辑
        RequestDispatcher dispatcher = request.getRequestDispatcher("/login.jsp");
        dispatcher.forward(request, response);
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //在处理字符串前进行字符编码转换
        String buttonClicked = new String(request.getParameter("action").getBytes("ISO-8859-1"), "UTF-8");
        System.out.println(buttonClicked);
        if ("登录".equals(buttonClicked)) {
            successHandler.handleRequest(request, response);
        } else if ("添加".equals(buttonClicked)) {
            addHandler.handleRequest(request, response);
        } else if ("编辑".equals(buttonClicked)){
            editorHandler.handleRequest(request,response);
        }else if("成功".equals(buttonClicked)){
            updetaler.handleRequest(request,response);
        }
    }
}
